﻿<?php

require_once(__DIR__ . '/ServerAPI.php');

class stSmsAuth
{
	// 注册的 key和 secret 定义好。
    const APP_KEY = 'b43a5c111d0f8782473d274056ae94fd';
    const APP_SECRET = 'ce3e2aef1398';
	
	// 发送验证码函数，传入手机号即可
    public static function cSendTo($a_Mpn)
    {
        $appKey = self::APP_KEY;
        $appSecret = self::APP_SECRET;
        $nonce = rand(100000, 999999);
        $curTime = time();
        $checkSum = sha1($appSecret . $nonce . $curTime);
        $data  = array(
            'mobile'=> $a_Mpn,
            'codeLen' => 6
        );
        $data = http_build_query($data);
        $opts = array (
            'http' => array(
                'method' => 'POST',
                'header' => array(
                    'Content-Type:application/x-www-form-urlencoded;charset=utf-8',
                    "AppKey:$appKey",
                    "Nonce:$nonce",
                    "CurTime:$curTime",
                    "CheckSum:$checkSum"
                ),
                'content' =>  $data
            ),
        );
        $context = stream_context_create($opts);
        $l_JsonStr = file_get_contents("https://api.netease.im/sms/sendcode.action", false, $context);
        return json_decode($l_JsonStr);
    }
}

